<template>
  <view>
    <view class="gui-list gui-margin-top gui-padding-x gui-bg-white">
      <view class="gui-list-items">

        <view class="gui-list-body gui-border-b" @tap="editAvater">
          <view class="gui-list-title">
            <text class="gui-list-title-text">头像</text>
            <view>
              <image class="gui-list-image ucenter-face-image" :src="userInfo.image?baseUrl+userInfo.image:userAvater"
                mode="aspectFill">
              </image>
            </view>
          </view>
        </view>
        <text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
      </view>
      <view class="gui-list-items">
        <view class="gui-list-body gui-border-b">
          <view class="gui-list-title">
            <text class="gui-list-title-text">用户名</text>
            <!-- <text class="gui-color-gray"></text> -->
            <input class="gui-list-arrow-right gui-icons gui-color-gray gui-flex1" @blur="editNickname"
              @confirm="editNickname" v-model="userInfo.nickName" />
          </view>
        </view>
        <text class="gui-list-arrow-right gui-icons gui-color-gray"> &#xe601;</text>
      </view>

    </view>

    <!-- <view class="gui-padding-x gui-bg-white gui-margin-top">
      <view class="gui-list-items" @click="getPhone">

        <view class="gui-list-body gui-border-b">
          <view class="gui-list-title">
            <text class="gui-list-title-text">帮助中心</text>
          </view>
        </view>
        <text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
      </view>
      <view class="gui-list-items" @click="goFeedback">

        <view class="gui-list-body gui-border-b">
          <view class="gui-list-title">
            <text class="gui-list-title-text">意见反馈</text>
          </view>
        </view>
        <text class="gui-list-arrow-right gui-icons gui-color-gray">&#xe601;</text>
      </view>
    </view> -->

  </view>
</template>
<script>
  // import bar from "@/pages/com/bar";
  import graceJS from '@/Grace6/js/grace.js';
  export default {
    // components: {
    // 	bar
    // },
    data() {
      return {
        contentHeight: 300,
        userInfo: {},
        userAvater: '/static/images/Ellipse66@2x.png',
        baseUrl: uni.gRequest.file,

      }
    },
    mounted() {
      // var user = uni.gRequest.checkLogin();
      // // console.log("是否登录", user)
      // if (user) {
      //   this.userInfo = user

      //   if (user.user_avater) {
      //     this.userAvater = uni.gRequest.server.replace('/app/', '') + user.user_avater;
      //   }

      // }
      this.userInfo = uni.getStorageSync('userInfo')
      var systemInfo = graceJS.system();
      this.contentHeight = systemInfo.windowHeight * 0.65;

    },
    methods: {

      // 上传图片
      async editAvater() {
        const res = await uni.chooseMedia({
          count: 1,
          mediaType: 'image',
        })
        wx.uploadFile({
          url: this.baseUrl + '/common/upload',
          filePath: res.tempFiles[0].tempFilePath,
          name: 'file',
          header: {
            Authorization: 'Bearer ' + this.userInfo.token,
          },
          success: async (result) => {
            // 处理返回的 json 数据
            const data = JSON.parse(result.data)
            // console.log(111, data);
            // 判断接口是否调用成功
            if (data.code !== 200) {
              return wx.showToast({
                icon: 'none',
                title: '上传图片失败!'
              })
            }
            // 渲染数据
            this.userInfo.image = data.fileName
            // const userInfo = uni.getStorageSync('userInfo')
            // userInfo.image = data.fileName
            uni.setStorageSync('userInfo', this.userInfo)
            const res = await uni.gRequest.get('/app/user/edit/image', {
              id: this.userInfo.userId,
              img: data.fileName
            })
            // console.log(123456, res);
          },
        })
      },
      editNickname() {
        // console.log('1111111111', this.userInfo);
        var self = this;
        uni.gRequest.get("/app/user/edit/nickname", {
          id: self.userInfo.userId,
          nickName: self.userInfo.nickName
        }).then(x => {
          uni.showToast({
            title: "修改成功"
          })
          uni.setStorageSync("userInfo", self.userInfo);
        });

      }

    }
  }
</script>
<style>

</style>
